/*
 * Copyright 2008 Nathan C Jones
 * 
 * This file is part of Fivehundred.
 * 
 * Fivehundred is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * Fivehundred is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * Fivehundred. If not, see <http://www.gnu.org/licenses/>. 
 */
package com.googlecode.fivehundred.game;

import com.googlecode.fivehundred.model.CardPile;
import com.googlecode.fivehundred.model.Player;
import com.googlecode.fivehundred.model.Team;


/**
 * Maintains entire game state and controls game flow.
 * 
 * @author Nathan C Jones
 */
public class Game {

	/** The pile used for dealing cards from. */
	private CardPile drawPile;

	/** The pile players play cards onto. */
	private CardPile discardPile;

	/** The first team in the game. */
	private final Team teamOne;

	/** The second team in the game. */
	private final Team teamTwo;

	/**
	 * Create a new game with the two teams.
	 * 
	 * @param teamOne the first team in the game.
	 * @param teamTwo the second team in the game.
	 */
	public Game(Team teamOne, Team teamTwo) {
		super();
		this.teamOne = teamOne;
		this.teamTwo = teamTwo;
	}

	public Player getNextPlayer() {
		return null;
	}

	public CardPile getDiscardPile() {
		return discardPile;
	}

	public void playGame() {
		while (!isGameComplete()) {
			
		}
	}

	/**
	 * Determine if the game is over. The game is over once either team has gone
	 * out by making or losing 500 points.
	 * 
	 * @return <code>true</code> if the game is complete.
	 */
	public boolean isGameComplete() {
		return teamOne.isOut() || teamTwo.isOut();
	}

	/**
	 * Get the team which has won the game.
	 * 
	 * @return the winning team, or <code>null</code> if no team has won yet.
	 */
	public Team getWinningTeam() {
		if (teamOne.hasWon() || teamTwo.hasLost()) {
			return teamOne;
		} else if (teamTwo.hasWon() || teamOne.hasLost()) {
			return teamTwo;
		} else {
			return null;
		}
	}
}
